<template>
  <div>
    <!-- 搜索栏区域 -->
    <el-card class="SearchCard" body-style="padding:0px">
      <el-row>
        <el-col :span="2">
          <div class="SearchTitle">条件搜索栏</div>
        </el-col>
        <el-col :span="4">
          <el-row>
            <el-col :span="10">
              <div class="SearchLable">搜索关键字</div>
            </el-col>

            <el-col :span="14">
              <div class="SearchLable">
                <el-input placeholder="请输入内容" v-model="queryInfo.srm" clearable @clear="clearEvent"></el-input>
              </div>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="2">
          <div class="SearchLable">
            <el-button size="medium" type="primary" @click="getSearchList()">搜索</el-button>
          </div>
        </el-col>
        <el-col :span="2">
          <div class="SearchLable">
            <el-button size="medium" @click="dialogVisible=true" type="primary">添加新药</el-button>
          </div>
        </el-col>
      </el-row>
    </el-card>
    <el-card class="TableCard" :body-style="{ padding: '0px' }">
      <div>
        <el-table
          :data="tableData"
          border
          :header-cell-style="{ 'text-align':'center',background: '#3F9DFD', color: '#FFF' }"
          :cell-style="{'text-align':'center'}"
          size="medium"
          stripe
          ref="table"
          :height="tableHeight"
          style="width: 100%;font-size:12px"
        >
          <el-table-column prop="drugCode" label="药品编码" width="100"></el-table-column>
          <!-- <el-table-column prop="name"
                           label="操作"
                           width="60">
            <el-button type="text"
                       size="mini"
                       @click="dialogVisible = true">编辑</el-button>
          </el-table-column>-->
          <el-table-column prop="drugName" label="药品名称"></el-table-column>

          <el-table-column prop="cbrand" label="商品名"></el-table-column>
          <el-table-column label="药品类型">
            <template slot-scope="scope">
              <div v-if="scope.row.nameType==8">西药</div>
              <div v-else-if="scope.row.nameType==2">草药</div>
              <div v-else-if="scope.row.nameType==6">中成药</div>
            </template>
          </el-table-column>
          <el-table-column prop="drugSpec" label="药品规格"></el-table-column>
          <el-table-column prop="compName" label="药品生产厂家" width="220"></el-table-column>
          <el-table-column prop="approvalCode" label="批准文号"></el-table-column>
          <el-table-column label="规则">
            <template slot-scope="scope">
              <el-button
                type="text"
                v-if="scope.row.adultDrugId!=0"
                @click="showRuleAdult(scope.row.adultDrugId)"
              >显示规则</el-button>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                type="text"
                v-if="scope.row.adultDrugId!=0"
                @click="deleteRuleAdult(scope.row.drugCode)"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[20, 50, 100]"
          :page-size="queryInfo.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="this.total"
          background
        ></el-pagination>
      </div>
    </el-card>
    <el-dialog title="添加新药" :visible.sync="dialogVisible" width="55%" :before-close="handleClose">
      <div>
        <el-form
          :inline="true"
          :model="addRuleAdultData"
          class="demo-form-inline"
          label-width="150px"
          label-position="right"
        >
          <el-form-item label="药品编码">
            <el-input v-model="addRuleAdultData.drugCode"></el-input>
          </el-form-item>
          <el-form-item label="药品名称">
            <el-input v-model="addRuleAdultData.drugName"></el-input>
          </el-form-item>
          <el-form-item label="给药途径ID">
            <el-input v-model="addRuleAdultData.routeIds"></el-input>
          </el-form-item>
          <el-form-item label="给药途径类型">
            <el-input v-model="addRuleAdultData.routeType"></el-input>
          </el-form-item>
          <el-form-item label="给药途径描述">
            <el-input v-model="addRuleAdultData.routeDesc"></el-input>
          </el-form-item>
          <el-form-item label="年龄低值">
            <el-input v-model="addRuleAdultData.ageLow"></el-input>
          </el-form-item>
          <el-form-item label="是否不等于年龄低值">
            <el-select v-model="addRuleAdultData.unequalLow">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="年龄低值单位">
            <el-select v-model="addRuleAdultData.ageLowUnit">
              <el-option
                v-for="item in dateUnit"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="年龄高值">
            <el-input v-model="addRuleAdultData.ageHigh"></el-input>
          </el-form-item>
          <el-form-item label="是否不等于年龄高值">
            <el-select v-model="addRuleAdultData.unequalHigh">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="年龄高值单位">
            <el-select v-model="addRuleAdultData.ageHighUnit">
              <el-option
                v-for="item in dateUnit"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="警示内容">
            <el-input v-model="addRuleAdultData.warning"></el-input>
          </el-form-item>
          <el-form-item label="文献资料">
            <el-input v-model="addRuleAdultData.abstractDesc"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addRuleAge()">新 增</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 显示一条规则 -->
  </div>
</template>
<script>
import {} from "@/api/rad";
export default {
  data() {
    return {
      tableHeight: 250,
      queryInfo: {
        srm: "",
        page: 1,
        pageSize: 20
      },
      total: 0,
      tableData: [],
      dialogVisible: false,
      addRuleAdultData: {
        drugCode: "",
        drugName: "",
        routeIds: "",
        routeType: "",
        routeDesc: "",
        ageLow: "",
        unequalLow: "",
        ageLowUnit: "",
        ageHigh: "",
        unequalHigh: "",
        ageHighUnit: "",
        slCode: "",
        warning: "",
        abstractDesc: ""
      },
      options: [
        {
          value: "1",
          label: "不等于"
        },
        {
          value: "0",
          label: "等于"
        }
      ],
      dateUnit: [
        {
          value: "周",
          label: "周"
        },
        {
          value: "月",
          label: "月"
        },
        {
          value: "年",
          label: "年"
        }
      ]
    };
  },
  // 监听浏览器变化
  mounted: function() {
    // this.$nextTick(function() {
    //   this.tableHeight =
    //     window.innerHeight - this.$refs.table.$el.offsetTop - 50;
    //   // 监听窗口大小变化
    //   let self = this;
    //   window.onresize = function() {
    //     self.tableHeight =
    //       window.innerHeight - self.$refs.table.$el.offsetTop - 50;
    //   };
    // });
  },
  created: function() {
    // this.();
  },
  methods: {
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(_ => {
          done();
        })
        .catch(_ => {});
    },
    handleSizeChange(newSize) {
      this.queryInfo.pageSize = newSize;
      // this.();
    },

    handleCurrentChange(newPage) {
      this.queryInfo.page = newPage;
      // this.();
    },
    // async () {
    //   let res = await this.$rad.({
    //     srm: this.queryInfo.srm,
    //     page: this.queryInfo.page,
    //     pageSize: this.queryInfo.pageSize
    //   });
    //   (this.tableData = res.rows), (this.total = res.total);
    //   console.log(res.rows);
    // },
    getSearchList() {},
    clearEvent() {}
  }
};
</script scoped>
<style>
.SearchCard {
  height: 50px;
  font-size: 12px;
}
.SearchTitle {
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-right: 1px solid #c2c2c2;
}
.SearchLable {
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.TableCard {
  margin-left: 3px;
  margin-top: 2px;
}
.block {
  text-align: center;
  margin-top: 12px;
  margin-bottom: 12px;
}
</style>